import React, { Component } from 'react';
import {
    View,
    StyleSheet,
    ScrollView
} from 'react-native';
import TopBar from '../../component/TopBar';
import SetttingItem from '../../component/SettingItem';
import MineHeaderView from './view/MineHeaderView';
import StorageUtil from '../../util/StorageUtil';
import Constants from '../../constant/Constants';
/**
 * 我的
 */
export default class MinePage extends React.PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            headerInfo: {

            }
        }
    }

    render() {
        return (
            <View style={Style.container}>
                <TopBar ref="tabbar" title='我的' showBack={true} onBackPress={() => { this.props.navigation.pop(); }} />
                <ScrollView>
                    <MineHeaderView headerInfo={this.state.headerInfo} />
                    <SetttingItem iconSource={require('../../img/icon_account_safe.png')} title='账号与安全'
                        showBottomLine={true} onPress={() => { this.onAccountSave() }} />
                    <SetttingItem iconSource={require('../../img/icon_fingerprint.png')} title='指纹登录'
                        showBottomLine={true} />
                    <SetttingItem iconSource={require('../../img/help_center.png')} title='帮助中心'
                        showBottomLine={true} style={Style.helpStyle} />
                    <SetttingItem iconSource={require('../../img/visit_colleague.png')} title='邀请同事使用车智赢+'
                        showBottomLine={true} />
                    <SetttingItem iconSource={require('../../img/contact_us.png')} title='联系之家线下顾问'
                        showBottomLine={true} />
                    <SetttingItem iconSource={require('../../img/icon_setting.png')} title='设置'
                        showBottomLine={true} style={Style.settingStyle} />
                </ScrollView>
            </View>
        );
    }
    /**
     * 账号安全
     */
    onAccountSave() {
        alert('账号安全');
    }

    componentDidMount() {
        //1.获取商家信息
        StorageUtil.get(Constants.KEY.KEY_LOGIN_INFO).then(result => {
            console.log(JSON.stringify(result));
            this.setState({
                headerInfo: {
                    iconTxt: '商',
                    title: result.nickname,
                    subTitle: result.rolenames
                }
            });
        }).catch(error => {
            console.log(error);
        });
    }

    /**
     * 跟进NickName获取显示头像
     */
    getHeadTextByNickName(nickName) {
        isNaN(nickName);
    }
}

const Style = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: Constants.COLOR.ColoirBackground
    },
    helpStyle: {
        marginTop: 5
    },
    settingStyle: {
        marginTop: 5
    }
});
